<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--<jsp:useBean id="clsConn" class="utility.connections" scope="session"></jsp:useBean>-->
<%@page import = "utility.connections" %>
<script type="text/javascript">
	function modify(formName)
	{
		var pattern = /[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]/;
		var number= /[0-9]/;
		var	codF=document.forms[formName].elements["codicefiscale"].value;
		var cognome=document.forms[formName].elements["cognome"].value;
		var nome=document.forms[formName].elements["nome"].value;
		if(codF.length!=16)
		{
			alert("ERROR lunghezza campo CodiceFiscale errata");
			return;
		}
		if(!pattern.test(codF))
		{	
			alert("ERROR forma campo CodiceFiscale errata");
			return;
		}
		if(nome.length==0||cognome.length==0)
		{
			alert("ERROR campo nome o cognome vuoto/i");
			return;
		}
		if(number.test(nome)||number.test(cognome))
		{
			alert("ERROR valore numerico riscontrato nel campo nome o cognome");
			return;
		}
		document.forms[formName].submit();	
	}
	function back()
	{
		document.form1.action="gestione_dipendente.jsp";
		document.form1.submit();
	}
</script>
<%! 
	String matricola="",codicefiscale="",cognome="",nome="",user="",qry=""; 
	ResultSet rs;
	String modify;
%>
<%
	if (session.getAttribute("user")==null)
		response.sendRedirect("loginerr.jsp");
	
	modify=request.getParameter("modify").toString();
	if (modify.equalsIgnoreCase("1"))
	{
		matricola=connections.doubleQuota(request.getParameter("matricola"));
		codicefiscale=connections.doubleQuota(request.getParameter("codicefiscale"));
		cognome=connections.doubleQuota(request.getParameter("cognome"));
		nome=connections.doubleQuota(request.getParameter("nome"));
		
		qry = "update personale set codicefiscale='" + codicefiscale + "',cognome='" + cognome + "',nome='" + nome +"' where matricola = "+ matricola;
		utility.connections.getStatement().executeUpdate(qry);
		System.out.println("stampo");
		
	}
	user = session.getAttribute("user").toString().toLowerCase();
	matricola=request.getParameter("matricola").toString().toLowerCase();
	
	qry = "select * from personale where matricola = "+matricola;
	rs = utility.connections.getStatement().executeQuery(qry);
	
	if (rs.next())
	{
		codicefiscale=rs.getString("codicefiscale");
		nome=rs.getString("nome");
		cognome=rs.getString("cognome");
	}
	else
	{
		matricola="";
		codicefiscale="";
		nome="";
		cognome="";
	}
	rs.close();
%>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>MODIFICA DIPENDENTE</title>
<script type="text/javascript" src="../../js/immagini.js"></script>
<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="js/immagini.js"></script>
</head>

<body>
<table width="700" height="422" border="0" align="center">
  <tr>
    <td align="center" valign="middle"></td>
  </tr>
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>
        
        </tr>
      <tr>
        <td class="style2"><p align="center"><strong>Modifica i dati </strong></p></td>
      </tr>
      
      <tr>
        <td class="style2">
          <form name="form1" method="post" action = "modifica_dipendente.jsp?modify=1">
          <table width="100%" border="0">
            <tr>
              <td width="16%">&nbsp;</td>
              <td width="27%"><div align="right">matricola:</div></td>
              <td width="32%"><input type="text" name="matricola" size="60" value="<%=matricola%>" readonly="readonly" ></input></td>
              <td width="25%">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><div align="right">codice fiscale :</div></td>
              <td><input type="text" name="codicefiscale" size="60" value="<%=codicefiscale%>" ></input></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><div align="right">nome:</div></td>
              <td><input type="text" name="nome" size="60" value="<%=nome%>" ></input></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><div align="right">cognome:</div></td>
              <td><input type="text" name="cognome" size="60" value="<%=cognome%>" ></input></td>
              <td>&nbsp;</td>
            </tr>
                        <tr>
        	<td class="style3">&nbsp;</td>
        	<td class="style3">&nbsp;</td>
        	<td class="style3">
		  	<input type="button" value="MODIFICA" onclick="javascript:modify('form1');"/>
		  	<input type="button" value="INDIETRO" onclick="javascript:back();"/>
            </td>
              <td>&nbsp;</td>
              <td><div align="right"></div></td>
             </tr>
            <tr>
              <td>&nbsp;</td>
              <td><div align="right"></div></td>
              <td>
                
                <div align="center">
				 </div></td></tr>
          </table>
          </form>
       		 
        </tr>
      <tr>
        <td class="style1"><div align="center"></div></td>
        </tr>
    </table>
  </tr>
  <tr>
    <td align="center" valign="middle">
	<%
		if(modify.equalsIgnoreCase("1"))
			out.println("RECORD MODIFICATO");
	%>
	</td>
  </tr>
  <tr>
    <td align="center" valign="middle" bgcolor="#000099"><div align="right" class="style4">MODIFICA DIPENDENTE </div></td>
  </tr>
</table>
</body>
</html>
